package xiaoqianlang.common;

/**
 * @Author：xiaoqianlang
 * @Package：xiaoqianlang.common
 * @Project：PasswordManage
 * @name：ApiResponse
 * @Date：2025/4/3/周四 22:14
 * @Filename：ApiResponse
 * 通用响应类，用于封装所有接口的返回值
 */
public class ApiResponse<T> {
    private int code;    // 状态码
    private String message; // 提示信息
    private T data;      // 数据

    public ApiResponse(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(200, "操作成功", data);
    }

    public static <T> ApiResponse<T> error(String message) {
        return new ApiResponse<>(500, message, null);
    }

    // Getter 和 Setter 方法
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}